//
//  EquipmentNameVC.m
//  AILock
//
//  Created by 谭亚明 on 2020/7/14.
//  Copyright © 2020 tym. All rights reserved.
//

#import "EquipmentUserNameVC.h"
#import "EquipmentService.h"
#import "UIimage+Extends.h"
#import "UIButton+Gradient.h"
@interface EquipmentUserNameVC ()

@property(nonatomic,weak) IBOutlet UITextField *equipName;

@property(nonatomic,weak) IBOutlet UIButton *subBtn;

@property(nonatomic,strong) EquipmentService *services;
@end

@implementation EquipmentUserNameVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addBackBtnFunc];
    
    
    self.subBtn.layer.masksToBounds = YES;
    self.subBtn.layer.cornerRadius = 5;
    
    [self.equipName addTarget:self action:@selector(changedTextField:) forControlEvents:UIControlEventEditingChanged];
    [self changedTextField:nil];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self addTitle:self.titleStr];
    self.equipName.text = self.nameStr;
}

-(void)changedTextField:(UITextField*)fid{
    if (self.equipName.text.length<1) {
        [self.subBtn setBackgroundImage:[UIImage imageWithColor:rgba(230, 230, 230) withSize:self.subBtn.bounds.size] forState:UIControlStateNormal];
    }else{
        [self.subBtn gradientButtonWithSize:CGSizeMake(300, 44) colorArray:@[(id)rgba(139, 175, 255),(id)rgba(76, 132, 255)] percentageArray:@[@(0.5),@(1)] gradientType:GradientFromLeftTopToRightBottom];
    }
}

-(EquipmentService*)services{
    if (_services == nil) {
        _services = [[EquipmentService alloc] init];
    }
    return _services;
}

-(IBAction)doSubmitAction:(id)sender{
    
    TYMWeak(self);
    [self.services getEquipmentEquipmentUserAuthId:self.equipMentID equipmentUserName:self.equipName.text completion:^(LMJBaseResponse * _Nonnull resp) {
        
        if (resp.code == 0) {
            [WHToast showMessage:@"修改成功" duration:2 finishHandler:^{
                [weakself.navigationController popViewControllerAnimated:YES];
            }];
        }else{
            [WHToast showMessage:resp.message duration:2 finishHandler:nil];
        }
    }];
}

@end
